package com.example.presentshopping.net.http;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ThreadUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.example.presentshopping.R;
import com.example.presentshopping.config.base.MyApplication;
import com.example.presentshopping.config.bean.LuckydrawBean;
import com.example.presentshopping.config.bean.YDClassifyItemBean;
import com.example.presentshopping.jpay.JPay;
import com.example.presentshopping.net.okhttp.CallBackUtil;
import com.example.presentshopping.net.okhttp.OkhttpUtil;
import com.example.presentshopping.ui.custom.LotteryView;
import com.example.presentshopping.ui.custom.Prize;
import com.example.presentshopping.utils.glide.GlideUtil;
import com.google.android.material.imageview.ShapeableImageView;


import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import okhttp3.Call;
import okhttp3.Callback;

/**
 * 请求参数。
 */
public class HttpRequest {
    // 全局请求头
    public static HashMap<String, Object> Headers(String contentType) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("accept", "*/*");// 数据接受类型
        if (!contentType.equals("") && contentType.length() != 0) {
            params.put("Content-Type", contentType);// 数据类型: X-WWW-FORM-URLENCODED
        }
        params.put("token", "IntentJumpUtils.getUsrToken()");// 公共参数，用户验证。
        return params;
    }

    public static HashMap<String, Object> waitChange(String key ,String val){
        HashMap<String, Object> params = new HashMap<>();
        params.put(key,val);
        return params;
    }



    //发送短信
    public static HashMap<String, Object> SendSms(String phone) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("mobile", phone);// phone	String	必填	手机号码
        return params;
    }

    // 用户登录
    public static HashMap<String, Object> Sendlogin(String phone, String code) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("mobile", phone);// phone	String	必填	手机号码
        params.put("code", code);// phone	String	必填	手机号码
        return params;
    }

    //获取商品列表
    public static HashMap<String, Object> getGoodsList(int type, int page, int limit) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("type", type);//1 推荐 2新品 3热销
        params.put("page", page);//
        params.put("limit", limit);//
        return params;
    }

    //获取拼图商品列表
    public static HashMap<String, Object> getTeamGoodsList(int type, int page, int limit) {
        HashMap<String, Object> params = new HashMap<>();
        // params.put("goods_name", type);//1 推荐 2新品 3热销
        params.put("page", page);//
        params.put("limit", limit);//
        return params;
    }

    //我的收益
    public static HashMap<String, Object> getTodatearnin(String type, int page, int limit) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("type", type);//1 推荐 2新品 3热销
        params.put("page", page);//
        params.put("limit", limit);//
        return params;
    }


    //获取商品详情
    public static HashMap<String, Object> getGoodsDetail(String id) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("id", id);//产品id
        return params;
    }

    //获取订单列表
    public static HashMap<String, Object> getOrderList(int is_team, String status, int page, int limit) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("is_team", is_team);//产品id
        params.put("status", status);//产品id
        params.put("page", page);//
        params.put("limit", limit);//
        return params;
    }

    //创建订单

    /**
     * goods_id	是	string	商品id
     * is_team	是	int	1拼团 2非拼团
     * number	是	int	购买数量 拼团强制1
     * team_type	否（普通下单不需要）	int	1单次 2无限
     * address_id	否	string	已设置默认地址可以不传
     * remark	否	string	备注
     */
    public static HashMap<String, Object> createOrder(String goods_id, String is_team, String number, String team_type, String address_id, String remark) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("goods_id", goods_id);
        params.put("is_team", is_team);
        params.put("number", number);
        params.put("team_type", team_type);
        params.put("address_id", address_id);
        params.put("remark", remark);
        return params;
    }

    //平台支付
    public static HashMap<String, Object> orderPlatform(String order_id, String password) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("order_id", order_id);
        params.put("password", password);
        return params;
    }

    //支付宝支付
    public static HashMap<String, Object> orderalipay(String order_id) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("order_id", order_id);
        return params;
    }

    //微信支付
    public static HashMap<String, Object> orderwxpay(String order_id, String code) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("order_id", order_id);
        params.put("code", code);
        return params;
    }

    //我的团队
    public static HashMap<String, Object> getMyteam(String team_type, String type, String order, String name, String page, String limit) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("team_type", team_type);
        params.put("type", type);
        params.put("order", order);
        params.put("name", name);
        params.put("page", page);
        params.put("limit", limit);
        return params;
    }
    //修改收货地址

    /**
     * @param id      否	string	在修改时必须 新增时不需要传
     * @param linkman 否	string	联系人
     * @param tel     否	string	电话
     * @param address 否	string	地址
     * @param auto    否	number	是否设为默认地址 传 1
     */
    public static HashMap<String, Object> editAddress(String id, String linkman, String tel, String address, String auto) {
        HashMap<String, Object> params = new HashMap<>();
        if (!TextUtils.isEmpty(id)) {
            params.put("id", id);
        }
        if (!TextUtils.isEmpty(id)) {
            params.put("auto", auto);
        }

        params.put("linkman", linkman);
        params.put("tel", tel);
        params.put("address", address);

        return params;
    }

    //修改支付密码
    public static HashMap<String, Object> gteditpwd(String password, String code) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("password", password);
        params.put("code", code);
        return params;
    }

    //提现申请
    public static HashMap<String, Object> applyWithdrawal(String ali_name, String amount,String payee_real_name) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("ali_name", ali_name);
        params.put("payee_real_name", payee_real_name);
        params.put("amount", amount);
        return params;
    }

    public static HashMap<String, Object> getGoodsCategory(String parentid) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("parentid", parentid);
        return params;
    }

    public static List<String> getTeli(List<YDClassifyItemBean.DataBean.ListBean> list) {
        List<String> ins = new ArrayList<>();
        for (YDClassifyItemBean.DataBean.ListBean sya : list) {
            ins.add(sya.getName());
        }
        return ins;
    }

    /**
     * category_id	是	int	商品类型id
     * goods_name	否	string	产品名 模糊搜索
     * page	否	number	xxx
     * limit	否	number	xxx
     */
    public static HashMap<String, Object> getCateGoods(String category_id, String goods_name, int page) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("category_id", category_id);
        params.put("goods_name", goods_name);
        params.put("page", page);
        params.put("limit", 10);
        return params;
    }

    /**
     * supplier_name	否	string	商家名称
     * page	否	number	xxx
     * limit	否	number	xxx
     */
    public static HashMap<String, Object> getSupplierList(String supplier_name, int page) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("category_id", supplier_name);
        params.put("page", page);
        params.put("limit", 10);
        return params;
    }

    /**
     * id	是	string	商家名称
     * goods_name	否	string	商品名称
     * page	否	number	xxx
     * limit	否	number	xxx
     */
    public static HashMap<String, Object> getSupplierGoodsList(String id, String goods_name, int page, int limit) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("goods_name", goods_name);
        params.put("page", page);
        params.put("limit", limit);
        return params;
    }
    /**
     * amount	是	double	红包金额
     * password	是	string	支付密码
     *
     * */
  public  static HashMap<String, Object> getInvitationCode(String amount,String password){
      HashMap<String, Object> params = new HashMap<>();
      params.put("amount", amount);
      params.put("password", password);
      return params;
  }
/**    id	是	string	获奖记录id
    linkman	是	string	联系人
    tel	是	string	联系电话
    address	是	string	收货地址*/
    public  static HashMap<String, Object> TurntableAddress(String id ,String linkman ,String tel,String address ){
        HashMap<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("linkman", linkman);
        params.put("tel", tel);
        params.put("address", address);
        return params;
    }
    public  static HashMap<String, Object> editUserInfo(String avatar){
        HashMap<String, Object> params = new HashMap<>();
        params.put("avatar", avatar);
        return params;
    }
  //通过url获取bitmap


    /**
     * 网络可用状态下，下载图片并保存在本地
     *
     * @param strUrl 图片网址

     * @return 图片
     */
    public synchronized static Bitmap getNetBitmap(String strUrl ,Context context) {
        final Bitmap[] bitmap = new Bitmap[1];
      Glide.with(context).asBitmap().load(strUrl).into(new SimpleTarget<Bitmap>() {
          @Override
          public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
               bitmap[0] = resource;
              MyApplication.bitmapList.add(resource);
          }
      });

        return bitmap[0];
    }

}
